package com.cn.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.Comparator;
import java.util.Date;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
    * 菜单表
    */
@ApiModel(value="com-cn-pojo-SysMenu")
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "sys_menu")
public class SysMenu {
    /**
     * 菜单/按钮ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    @ApiModelProperty(value="菜单/按钮ID")
    private Long id;

    /**
     * 上级菜单ID
     */
    @TableField(value = "parent_id")
    @ApiModelProperty(value="上级菜单ID")
    private Long parentId;

    /**
     * 菜单/按钮名称
     */
    @TableField(value = "menu_name")
    @ApiModelProperty(value="菜单/按钮名称")
    private String menuName;

    /**
     * 前端菜单路由URL
     */
    @TableField(value = "router_url")
    @ApiModelProperty(value="前端菜单路由URL")
    private String routerUrl;

    /**
     * 权限标识
     */
    @TableField(value = "perms")
    @ApiModelProperty(value="权限标识")
    private String perms;

    /**
     * 图标
     */
    @TableField(value = "icon")
    @ApiModelProperty(value="图标")
    private String icon;

    /**
     * 类型 0菜单 1按钮
     */
    @TableField(value = "type")
    @ApiModelProperty(value="类型 0菜单 1按钮")
    private String type;

    /**
     * 排序
     */
    @TableField(value = "order_num")
    @ApiModelProperty(value="排序")
    private Long orderNum;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    @ApiModelProperty(value="创建时间")
    private Date createTime;

    /**
     * 修改时间
     */
    @TableField(value = "update_time")
    @ApiModelProperty(value="修改时间")
    private Date updateTime;

    /**
     * 0：不可用，1：可用
     */
    @TableField(value = "available")
    @ApiModelProperty(value="0：不可用，1：可用")
    private Integer available;

    /**
     * 0:不展开，1：展开
     */
    @TableField(value = "open")
    @ApiModelProperty(value="0:不展开，1：展开")
    private Integer open;

    //因为此字段不属于表内字段，所以加上 @TableField(exist = false)
    @TableField(exist = false)
    private List<SysMenu> childMenus;

    /**
     * 排序，根据order排序
     */
    public static Comparator<SysMenu> order(){
        Comparator<SysMenu> comparator=(o1, o2) -> {
            if (o1.getOrderNum()!=o2.getOrderNum())
            {
                return (int) (o1.getOrderNum() - o2.getOrderNum());
            }
            return 0;
        };
        return comparator;
    }


    public static final String COL_ID = "id";

    public static final String COL_PARENT_ID = "parent_id";

    public static final String COL_MENU_NAME = "menu_name";

    public static final String COL_ROUTER_URL = "router_url";

    public static final String COL_PERMS = "perms";

    public static final String COL_ICON = "icon";

    public static final String COL_TYPE = "type";

    public static final String COL_ORDER_NUM = "order_num";

    public static final String COL_CREATE_TIME = "create_time";

    public static final String COL_UPDATE_TIME = "update_time";

    public static final String COL_AVAILABLE = "available";

    public static final String COL_OPEN = "open";
}